using System;
using System.Collections.Generic;
using Pegasus.Data.SqlClient;

namespace RollManager.Library
{
    /// <summary>
    /// Class representing service to database.
    /// </summary>
    public partial class Database
    {
        private static SqlDatabaseConnection s_dbConnection;

        public static void Init( string dbServer, string dbName )
        {
            s_dbConnection = new SqlDatabaseConnection( dbServer, dbName );
        }

        public static List<DevLevel> GetDevLevels()
        {
            return runMapper<DevLevel>( "GetDevLevels" );
        }

        private static List<T> runMapper<T>(string storedProc, params object[] args) where T : new()
        {
            SqlObjectMapper<T> mapper = new SqlObjectMapper<T>( s_dbConnection );
            return mapper.ExecuteStoredProc( storedProc, args );
        }

        private static void runQuery(string storedProc, params object[] args)
        {
            using( SqlDatabaseAccess access = s_dbConnection.CreateDatabaseAccess() )
            {
                access.StoredProcNonQuery( storedProc, args );
            }
        }
    }
}
